#ifndef _PCA9685_H_
#define _PCA9685_H_

#include"STC15FXXXX.H"
#include"GPIO.H"
#include"delay.h"        
#include <intrins.h>  
#include <stdio.h>
#include <math.h>
#include "Timer_0.h"
#include "USART.h"
#include "I2C.H"



#define PCA9685_INTERRPT 1

#define PCA9685_adrr 0x80//  1+A5+A4+A3+A2+A1+A0+w/r 
#define PCA9685_SUBADR1 0x2
#define PCA9685_SUBADR2 0x3
#define PCA9685_SUBADR3 0x4


#define PCA9685_MODE1 0x00
#define PCA9685_PRESCALE 0xFE


#define LED0_ON_L 0x06
#define LED0_ON_H 0x07
#define LED0_OFF_L 0x08
#define LED0_OFF_H 0x09


#define ALLLED_ON_L 0xFA
#define ALLLED_ON_H 0xFB
#define ALLLED_OFF_L 0xFC
#define ALLLED_OFF_H 0xFD
#define PCA9685_INTERRPT 1

#define PCA9685_adrr 0x80//  1+A5+A4+A3+A2+A1+A0+w/r 
#define PCA9685_SUBADR1 0x2
#define PCA9685_SUBADR2 0x3
#define PCA9685_SUBADR3 0x4


#define PCA9685_MODE1 0x00
#define PCA9685_PRESCALE 0xFE


#define LED0_ON_L 0x06
#define LED0_ON_H 0x07
#define LED0_OFF_L 0x08
#define LED0_OFF_H 0x09


#define ALLLED_ON_L 0xFA
#define ALLLED_ON_H 0xFB
#define ALLLED_OFF_L 0xFC
#define ALLLED_OFF_H 0xFD



#define GPIO_SCL  P2^1 //PCA9685时钟线
#define GPIO_SDA P2^0  //PCA9685数据线

#define JI_XIE_BI_INIT 66 //机械臂停止
#define STAT 55
#define FOW_CONFIG 1    //前进
#define BACK_CONFIG 2   //后退
#define LEFT_CONFIG 3   //向左
#define RIGHT_CONFIG 4  //向右

#define right_up_move   0 //右机械腿抬起标志
#define left_up_move    1 //左机械腿抬起标志
#define right_down_move 6 //右腿机械落下标志
#define left_down_move  7 //左机械腿落下标志
#define right_f_move    2 //右腿前进
#define left_f_move     3 //左腿前进
#define right_b_move    4 //右腿后退
#define left_b_move     5 //左腿后退

#define TURE 1
#define NO_TURE 0





typedef  unsigned char uchar;        
typedef  unsigned int   uint;        


/*
    舵机参数
*/
typedef struct servo_com
{
    u8 num;         //舵机线路
    float angle_stat;  //舵机运动状态
}servo_com;
/*
   360 舵机参数
*/
typedef struct servo_360_com
{
    u8 num;         //舵机线路
    u8 speed;//速度
    u16 time; //时间
    u8 flag;  //舵机运动状态
}servo_360_com;
/*
    PCA9685初始化
*/
void PCA9685_Init();
/*  
    舵机角度控制

    @param mun           PCA9685引脚
    @param target_angle  目标角度   
 
 */

void servo_control(uchar num, uchar angle);

/*  
    舵机角度速度控制

    @param servo         舵机参数
    @param target_angle  目标角度   
 
 */



#define DEFUAL_ANGLE 90.0f
#define DEFUAL_INC 1

typedef struct
{
    uchar channle;
    float target_angle;
    float acc_angle;
    float inc;
    u8 flag;
}StreetMotor;

extern StreetMotor STMotor[5];

void PCA_Init(void);
uchar speed_servo_control(u8 num,StreetMotor*STMotor);
#endif

